//
//  BGStatusRetweetView.swift
//  WeiboSwift
//
//  Created by 战场原黑仪 on 16/7/25.
//  Copyright © 2016年 战场原黑仪. All rights reserved.
//

import UIKit
import SnapKit

class BGStatusRetweetView: UIView {
    
    // 记录当前原创微博的底部约束
    private var retweetViewBottomConstraint:Constraint?
    
    var cellModel: BGHomeCellModel? {
        didSet{
            contentLabel.text = cellModel?.statusModel?.retweeted_status?.text
            
            //图片
            //移除约束
            retweetViewBottomConstraint?.uninstall()
            //如果有图片
            if cellModel?.statusModel?.retweeted_status?.pic_urls?.count>0 {
                //赋值
                picView.picsModel = cellModel?.statusModel?.retweeted_status?.pic_urls
                //更新约束
                self.snp_makeConstraints(closure: { (make) in
                    self.retweetViewBottomConstraint = make.bottom.equalTo(picView).offset(ViewMargin_S).constraint
                })
                
                picView.hidden = false
            }else {
                
                self.snp_makeConstraints(closure: { (make) in
                    self.retweetViewBottomConstraint = make.bottom.equalTo(contentLabel).offset(ViewMargin_S).constraint
                })
                
                picView.hidden = true
            }
        }
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        setupLayout()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: - 加载控件
    private func setupUI() {
        backgroundColor = Main_Color
        addSubview(contentLabel)
        addSubview(picView)
        
    }
    
    private func setupLayout() {
        contentLabel.snp_makeConstraints { (make) in
            make.top.leading.equalTo(self).offset(ViewMargin_S)
            make.trailing.equalTo(self).offset(-ViewMargin_S)
        }
        
        picView.snp_makeConstraints { (make) in
            make.top.equalTo(contentLabel.snp_bottom).offset(ViewMargin_S)
            make.leading.equalTo(contentLabel).offset(ViewMargin_S)
        }
        
        self.snp_makeConstraints { (make) in
            self.retweetViewBottomConstraint = make.bottom.equalTo(picView).offset(ViewMargin_S).constraint
        }
    }
    
    //MARK: - 懒加载
    private lazy var contentLabel: UILabel = UILabel(textColor: UIColor.darkGrayColor(), textFontSize: 15, maxWidth: SCREEN_W - 20)
    
    private lazy var picView: BGOriginalPicView = BGOriginalPicView()
    
}
